package org.oa.controller.work;
import java.util.List;

import javax.servlet.http.HttpSession;
import org.oa.common.WebConstant;
import org.oa.dto.User;
import org.oa.dto.Work;
import org.oa.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("work")
public class WorkController {
	@Autowired
	private WorkService workService;
	
	@RequestMapping(value="ajaxGetWorkByList")
	@ResponseBody
	public List<Work> ajaxGetWorkByList(HttpSession session){
		User user=(User)session.getAttribute(WebConstant.USER);
		return workService.getWorkByuserId(user.getUserId());
	}
	@RequestMapping("getWorkList")
	public String  getWorkList(HttpSession session,Model data){
		User user=(User)session.getAttribute(WebConstant.USER);
		List<Work> workList=workService.getWorkByuserId(user.getUserId());
		data.addAttribute("workList", workList);
		return "work/workList";
	}
	
	@RequestMapping(value="getWork")
	public String getWork(Long workId,Model data){
		Work work=workService.getWork(workId);
		data.addAttribute("work", work);
		return "work/workEdit";
	}
	
	@RequestMapping(value="ajaxUpdateWork")
	@ResponseBody
	public boolean ajaxUpdateWork(Work work){
		return workService.UpdateWork(work);
		
	}
}
